<html>
<head>
<title>Check the security contexts of about:blank and empty documents. (Adapted from LayoutTests)</title>
<script type="text/javascript" src="/shared/scripts/testcase.js"></script>
<script type="text/javascript">
if (window.addEventListener) {
	window.addEventListener('load', f, false);
} else if (window.attachEvent) {
	window.attachEvent('onload', f);
} else {
	window.onload = f;
}

function f() {
	var tc = new TestCase();
	tc.clearCookies(); // clear cookies
	tc.input = 'document properties before document.open, after document.open and after document.close.';
	tc.description = 'Check the security contexts of about:blank and empty documents. (Adapted from LayoutTests)';
	tc.expected_result = "context updated";
	document.cookie = 'cookie=parent';
	tc.test_passed = 'true';
	
	try {
		tc.output +='--- Test begins ---\n';
		tc.output +='* "about:blank"\n';
		tc.output +='document.URL = ' + frames[0].document.URL + '\n';
		tc.output +='document.baseURI = ' + frames[0].document.baseURI + '\n';
		tc.output +='document.cookie = ' + frames[0].document.cookie + '\n';
		tc.output +='* ""\n';
		tc.output +='document.URL = ' + frames[1].document.URL + '\n';
		tc.output +='document.baseURI = ' + frames[1].document.baseURI + '\n';
		tc.output +='document.cookie = ' + frames[1].document.cookie + '\n';
		tc.output +='--- After document.open() ---\n';
	} catch(e) {
		tc.output += 'exception occurred reading document properties: ' + tc.outputException(e);
		tc.result = 'unsupported';
	}

	try {
		frames[0].document.open();
		frames[1].document.open();
		tc.output +='* "about:blank"\n';
		tc.output +='document.URL = ' + frames[0].document.URL + '\n';
		tc.output +='document.baseURI = ' + frames[0].document.baseURI + '\n';
		tc.output +='document.cookie = ' + frames[0].document.cookie + '\n';
		tc.output +='* ""\n';
		tc.output +='document.URL = ' + frames[1].document.URL + '\n';
		tc.output +='document.baseURI = ' + frames[1].document.baseURI + '\n';
		tc.output +='document.cookie = ' + frames[1].document.cookie + '\n';
		if (frames[0].document.URL.indexOf('about:blank') != -1 ||
			frames[0].document.baseURI.indexOf('about:blank') != -1 ||
			frames[1].document.URL.indexOf('about:blank') != -1 || 
			frames[1].document.baseURI.indexOf('about:blank') != -1) {
			
			tc.test_passed = 'false';
			tc.result = 'security context still set to about:blank after open';
		}
	} catch(e) {
		tc.output += 'exception occurred opening document: ' + tc.outputException(e);
	}
	
	try {
		tc.output +='--- After document.close() ---\n';
		frames[0].document.close();
		frames[1].document.close();
		tc.output +='* "about:blank"\n';
		tc.output +='document.URL = ' + frames[0].document.URL + '\n';
		tc.output +='document.baseURI = ' + frames[0].document.baseURI + '\n';
		tc.output +='document.cookie = ' + frames[0].document.cookie + '\n';
		tc.output +='* ""\n';
		tc.output +='document.URL = ' + frames[1].document.URL + '\n';
		tc.output +='document.baseURI = ' + frames[1].document.baseURI + '\n';
		tc.output +='document.cookie = ' + frames[1].document.cookie + '\n';
		tc.output +='--- Test ends ---\n';
		if (frames[0].document.URL.indexOf('about:blank') != -1 ||
			frames[0].document.baseURI.indexOf('about:blank') != -1 ||
			frames[1].document.URL.indexOf('about:blank') != -1 || 
			frames[1].document.baseURI.indexOf('about:blank') != -1) {
			
			if (tc.test_passed == 'false') {
				tc.result += ' and close';
			} else {
				tc.test_passed = 'false';
				tc.result = 'security context set to about:blank after close';
			}
		}
	} catch(e) {
		tc.output += 'exception occurred closing document: ' + tc.outputException(e);
	}
	if (tc.test_passed == 'true') {
		tc.result = 'context updated';
	}
	tc.clearCookies(); // clear cookies
	tc.saveTest(); // save the test results.
}
</script>
</head>
<body>
	<iframe src="about:blank"></iframe><br>
	<iframe src=""></iframe><br>
</body>
</html>